/*
 * @lc app=leetcode.cn id=590 lang=cpp
 *
 * [590] N 叉树的后序遍历
 */

// @lc code=start
/*
// Definition for a Node.
class Node {
public:
    int val;
    vector<Node*> children;

    Node() {}

    Node(int _val) {
        val = _val;
    }

    Node(int _val, vector<Node*> _children) {
        val = _val;
        children = _children;
    }
};
*/
#include <bits/stdc++.h>
using namespace std;
class Solution
{
    vector<int> ans;
    void post(Node *root)
    {
        if (root)
        {
            if (root->children.size())
            {
                for (auto n : root->children)
                    post(n);
            }

            ans.push_back(root->val);
        }
    }

public:
    vector<int> postorder(Node *root)
    {
        post(root);

        return ans;
    }
};
// @lc code=end
